#!/bin/bash

if [ "$1" = "chromium" ]; then
   NAME="Chromium Web Browser"
   ABOUT="Chromium is a free and open source version of
the famous Chrome browser, developed by Google."
   EXECUTABLE="/usr/bin/chromium"
   if [ "$(uname -m)" = "i686" ]; then
      PARAMS="--disable-seccomp-filter-sandbox"
   else
      PARAMS=""
   fi
   INSTALL="wget -c -O /tmp/05-chromium.sb 'https://slax.org/download-web-browser.php?b=slackware&v=$(cat /etc/slax-version | tr -s " " "_")' && slax activate /tmp/05-chromium.sb && rm /tmp/05-chromium.sb"
   POSTINSTALL=""
   GUEST=true
fi

shift

# ------------------------------------------------
#   do not touch anything below this line
# ------------------------------------------------

if [ "$ABOUT" != "" ]; then
   ABOUT="$ABOUT

"
fi


if [ "$EXECUTABLE" = "" ]; then
   exit
fi


if [ ! -f "$EXECUTABLE" ]; then

   if [ $(uname -m) != 'x86_64' -a "$ONLY64" = "true" ]; then
      gtkdialog -i /usr/share/icons/HighContrast/16x16/status/dialog-warning.png  -t Error -m "$NAME only works in 64bit version of Slax" -y OK
      exit 1
   fi

   if gtkdialog -i /usr/share/icons/HighContrast/16x16/status/dialog-question.png -t Question -m "$ABOUT$NAME is not yet installed.
Do you like to download and install it now?" -y Yes -n No; then
      xterm -ls -e bash --login -c -- "$INSTALL; sleep 2; $POSTINSTALL"
   fi
fi


if [ -f "$EXECUTABLE" ]; then

   fbstartupnotify

   if [ "$GUEST" = "true" -a "$EUID" -eq 0 ]; then
      xhost + >/dev/null 2>/dev/null
      exec su -c "$EXECUTABLE $PARAMS "$@""  guest
   fi

   exec "$EXECUTABLE" "$@"

fi
